<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/2/25
 * Time: 17:20
 */

namespace App;


use Illuminate\Database\Eloquent\Model;

class Dynamic extends Model
{
    // 图片类型动态
    const PHOTO = 1;
    // 视频类型动态
    const VIDEO = 2;

    // 动态状态正常
    const ONLINE = 1;
    // 动态被隐藏
    const OFFLINE = 0;

    // 表名称
    protected $table = 'dynamic';
    // 开启自动时间戳
    public $timestamps = true;
    // 日期都存储为时间戳
    protected $dateFormat = 'U';

    public function dynamicPhoto()
    {
        return $this->hasMany('App\DynamicPhoto', 'dynamic_id', 'id');
    }

    public function dynamicVideo()
    {
        return $this->hasMany('App\DynamicVideo', 'dynamic_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo('App\Users', 'user_id', 'id');
    }

    public function dynamicComment()
    {
        return $this->hasMany('App\DynamicComment', 'dynamic_id', 'id');
    }

    public function userPraiseDynamic()
    {
        return $this->hasMany('App\UserPraiseDynamic', 'dynamic_id', 'id');
    }

    public function city()
    {
        return $this->hasOne('App\City', 'code', 'citycode');
    }

    public function praisedUser()
    {
        return $this->belongsToMany('App\Users', 'user_praise_dynamic', 'dynamic_id', 'user_id');
    }
}